1. /* slfldiv2.cpp by K.Tsuru */
  2. // funstion ID = 235 DRADIX, BRADIX
  3. #ifndef SN_H
  4. #include "sn.h"
  5. #endif
  6. /***************************
  7. SLong and SInteger calsses
  8. It divides by 2.
  9. ****************************/
  10. SLong LDiv2(const SLong& n){
  11. SLong result(n);
  12. uint rh = n.Head(), rt = n.Tail();
  13. if(rh == 0){ //only one figure including n = 0
  14. if( (result.figure[0] = n.figure(0)/2) == 0 ) result.SetSign(0);
  15. return result; // n = 0 or 1
  16. }
  17. fType rem = 0, u; // rem : remainder
  18. fType rdx = n.Radix();
  19. fType* rv = result.figure.Elements();
  20. #ifndef NDEBUG
  21. result.figure(rh);
  22. #endif
  23. for(int i = (int)rh; i >= (int)rt; i--) {
  24. u = rv[i];
  25. if(rem) u += rdx;
  26. rem = u & 1; // rem = 0 or 1
  27. rv[i] = u / 2;
  28. }
  29. if(rem && rt){ rt--; rv[rt] = rdx/2; } // rem = 1
  30. //get figure positions
  31. while(!rv[rh]) rh--;
  32. result.aHead = rh;
  33. #ifndef NDEBUG
  34. result.figure(rh);
  35. #endif
  36. //[caution] 24 0000....0001 / 2 ===> 12 0000 ... 0000
  37. while(!rv[rt]) rt++;
  38. result.aTail = rt;
  39. return result;
  40. }

slfldiv2.cpp : last modifiled at 2017/03/13 14:32:00(1,034 bytes)
created at 2017/10/07 10:26:50
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).